#include "systemfontsize.h"
#include <QDebug>
#include <QApplication>
#include <QFontMetrics>

SystemFontSize::SystemFontSize(QObject *parent) : QObject(parent)
{
    changeFontSize();
}

SystemFontSize::~SystemFontSize() {}

SystemFontSize *SystemFontSize::getInstance()
{
    static SystemFontSize systemFontSize;
    return &systemFontSize;
}

void SystemFontSize::changeFontSize()
{
    connect(kdk::GsettingMonitor::getInstance(), &kdk::GsettingMonitor::systemFontSizeChange, this, [=]() {
        getSystemFontSize();
        getSystemFontHeight();
        Q_EMIT signalChangeFontSize();
    });
    return;
}

void SystemFontSize::getSystemFontSize()
{
    /* 获取系统初始字体 */
    int systemFontSize = kdk::GsettingMonitor::getSystemFontSize().toInt();
    m_font12pxToPt = (systemFontSize * (12.00 / 11)) - 3;
    m_font16pxToPt = (systemFontSize * (16.00 / 11)) - 3;
    qInfo() << "system font size : " << systemFontSize;
    return;
}

QFont SystemFontSize::getFontSize12px()
{
    QFont font;
    font.setPointSizeF(m_font12pxToPt);
    return font;
}

QFont SystemFontSize::getFontSize16px()
{
    QFont font;
    font.setPointSizeF(m_font16pxToPt);
    return font;
}

int SystemFontSize::getSystemFontHeight()
{
    QFont font; //获取系统字体大小
    font = QApplication::font();
    QFontMetrics fm(font);
    int height = fm.height();
    int systemFontHeight = height * 2 + 6;
    qDebug() << "+++++systemFontHeight+++++++++++++++++" << systemFontHeight;
    return systemFontHeight;
}
